/*************************************************************
 * Title: 
 * Description: 
 * Author: Snow Huang
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com
 * CreateTime: 2010-8-1 下午03:26:23
 * Copyright © 落羽社区 All right reserved
 ************************************************************/
package snow.core.util.toolkit;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.hibernate.criterion.DetachedCriteria;

import snow.core.domain.query.Order;
import snow.core.domain.query.Query;

/**
 * 
 */
public class HibernateHelper {

	public static void addCriteria(DetachedCriteria detachedCriteria, Query<?> query) {
		if (detachedCriteria == null || query == null) {
			return;
		}
	}

	public static void addOrder(DetachedCriteria criteria, List<Order> orders) {
		if (CollectionUtils.isEmpty(orders) || criteria == null) {
			return;
		}
		for (Order order : orders) {
			String propertyName = order.getPropertyName();
			if (order.isAscending()) {
				criteria.addOrder(org.hibernate.criterion.Order.asc(propertyName));
			} else {
				criteria.addOrder(org.hibernate.criterion.Order.desc(propertyName));
			}
		}
	}
}
